package com.example.fbi_text.Acitivity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;

import com.example.fbi_text.R;
import com.example.fbi_text.bean.Product;
import com.example.fbi_text.views.ProductDetailFragment;

public class ProductDetailActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_detail);

        Product product = getIntent().getParcelableExtra("product");
        if (product == null) {
            finish();
            return;
        }

        // 仅在第一次创建时添加Fragment
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container, ProductDetailFragment.newInstance(product))
                    .commit();
        }
    }
}
